#ifndef _DBG_FUNC_H_H
#define _DBG_FUNC_H_H

#include "sys_init.h"

#ifdef __cplusplus
extern "C"
{
#endif

	typedef struct
	{
		char **argv_buff;
		char *cmd_buff;
		int argv_len_max;
		int cmd_buff_size;
	} shell_def_type;

	typedef struct
	{
		const char *name;
		int (*func)(int, char *[]);
		const char *txt;
	} func_info_type;

#define SHELL_FUN_BASE_EXPORT(fn, level, txt)                                           \
	extern int fn(int argc, char *argv[]);                                              \
	OBJ_USED const func_info_type __dbg_func_##fn OBJ_SECTION(".app_fn.dbg." level) = { \
		#fn,                                                                            \
		fn,                                                                             \
		txt}

#ifdef DBG_EN
#if DBG_EN > 0
#define DBG_FUN_EXPORT(fn) SHELL_FUN_BASE_EXPORT(fn, "2." #fn, (char*)0)
#define DBG_FUNX_EXPORT(fn, txt) SHELL_FUN_BASE_EXPORT(fn, "2." #fn, txt)
#else
#define DBG_FUN_EXPORT(...)
#endif
#else
#define DBG_FUN_EXPORT(...)
#endif

#define SHELL_FUN_EXPORT(fn) SHELL_FUN_BASE_EXPORT(fn, "2." #fn, (char*)0)
#define SHELL_FUNX_EXPORT(fn, txt) SHELL_FUN_BASE_EXPORT(fn, "2." #fn, txt)

#ifdef __cplusplus
}
#endif

const shell_def_type *shell_config(const shell_def_type *sh);
int shell_fun_list_exe(const char *cmd);
void shell_iter(void (*iter)(volatile const func_info_type *volatile fun, char c), char c);

#endif 
